import React, { Component } from 'react'

export default class LifeCycle3 extends Component {
  constructor(){
    super()
    this.state={
        count:0
    }
    console.log('********1、constructor***********');
  }
  render() {
    console.log('********2、render***********');
    return (
      <div>
        <h1>组件的卸载阶段的演示</h1>
        <h2>{this.state.count}</h2>
        <button onClick={()=>{
            this.setState({count:this.state.count+1})
        }}>+</button>
      </div>
    )
  }
  componentDidMount(){
    console.log('********3、componentDidMount***********');
    this.timers=setInterval(() => {
        console.log('--------我是定时器，我还活着----------------');
        this.setState({
            count:this.state.count+1
        })
    }, 1000);
  }
  componentDidUpdate(){
    console.log('********4、componentDidUpdate***********');
  }
  componentWillUnmount(){
    console.log('********5、componentWillUnmount***********');
    //销毁间隔定时器
    clearInterval(this.timers)
  }
}
